extends Skill


var utils = null
var disableLvUp = false
func _init():
	._init()
	if sys.has_node("VEBase"):
		utils = sys.get_node("VEBase").utils

#获得单元格附近的友军
func getCellAlly(cell, ran = 1):
	var chas = []
	for i in sys.batScene.getCellChas(cell, ran):
		if i != null and i.team == masCha.team: 
			chas.append(i)
	return chas

#获得单元格附近的敌军
func getCellEnemy(cell, ran = 1):
	var chas = []
	for i in sys.batScene.getCellChas(cell, ran):
		if i != null and i.team != masCha.team: 
			chas.append(i)
	return chas

#获得随机敌人
func getRandomEnemy():
	if not is_instance_valid(sys.batScene):return null
	return sys.rndListItem(sys.batScene.getAllEnemys(masCha.team))
func _process(delta):
	._process(delta)
	if cd != 0 and masCha.get("silenceTime") != null and masCha.get("silenceTime") > 0 and masCha.yunTime <= 0:
		#沉默判定，用于补偿上一步被增加的cdVal
		cdVal -= mas.cdSpd * delta

#强制杀死一个角色
func forceKill(cha):
	forceHurt(cha, cha.maxHp + cha.ward + 500)

#强制造成伤害，无视一切判定
func forceHurt(cha, value):
	var atkInfo = masCha.newAtkInfo(cha, value, HURTTYPE.REAL, ATKTYPE.EFF, self)
	atkInfo.finalVal = value
	return masCha.directHurt(atkInfo)

#策反敌人
func defectCha(cha):
	var hp = cha.hp
	forceKill(cha)
	var scha = masCha.summCopy(cha, cha.cell)
	scha.hp = hp

#目标角色是否有亡语技能
func hasDeathWord(cha):
	for i in cha.skills.items:
		if i.dec.find("<亡语>") > -1:
			return true
	return false

#施加buff，若目标已有此buff，则不会施加
func castBuffIfNull(cha, bid, lv):
	var bf = cha.hasAff(bid)
	if bf == null:
		return masCha.castBuff(cha, bid, lv)
	return bf
func sortByMaxHp(a,b):
	return  a.maxHp < b.maxHp

func sortByMaxHpDesc(a,b):
	return  a.maxHp > b.maxHp

func sortByHp(a,b):
	return (!a.isSumm && b.isSumm && a.maxHp - a.hp > 50) || a.hp / a.maxHp < b.hp / b.maxHp

func sortByNowHp(a,b):
	return (!a.isSumm && b.isSumm && a.maxHp - a.hp > 50) || a.hp < b.hp

func sortByHpDesc(a,b):
	return (!a.isSumm && b.isSumm && a.maxHp - a.hp > 50) || a.hp / a.maxHp > b.hp / b.maxHp

func sortByAtkDesc(a,b):
	return a.atk > b.atk

func sortByMatkDesc(a,b):
	return a.matk > b.matk

func sortByAtk(a,b):
	return a.atk < b.atk

func sortByMatk(a,b):
	return a.matk < b.matk
	
func sortByLv(a,b):
	return a.lv < b.lv

func sortByLvDesc(a,b):
	return a.lv > b.lv

func sortByAllAtkDesc(a,b):
	return a.atk + a.matk > b.atk + b.matk

func sortByDef(a,b):
	return a.def < b.def

func sortByRan(a,b):
	return a.ran < b.ran

func sortByDistanceDesc(a, b):
	return masCha.distanceTo(a) > masCha.distanceTo(b)	

func sortByDistance(a, b):
	return masCha.distanceTo(a) < masCha.distanceTo(b)

func sortByDefDesc(a,b):
	return a.def > b.def	
		
